package com.sphd.Restaurant.adapters;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.Restaurant.R;
import com.sphd.Restaurant.infos.Dishes;
import com.sphd.Restaurant.infos.RestaurantInfo;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Hu on 2016/10/11.
 */

public class AffirmAdapter extends BaseQuickAdapter<Dishes> {
    RestaurantInfo restaurantInfo;
    public AffirmAdapter(List<Dishes> data, RestaurantInfo restaurantInfo) {
        super(R.layout.affirm_item, data);
        this.restaurantInfo=restaurantInfo;
    }

    @Override
    protected void convert(BaseViewHolder helper, Dishes item) {
        helper.setText(R.id.dis_name, item.getDishes_name())
                .setText(R.id.dis_no, "x" + item.getOrder_no())
                .setText(R.id.dis_price, turn(item.getDishes_price() * item.getOrder_no(), 1).toString())
                .setText(R.id.dis_viprice, turn(item.getDishes_price() * item.getOrder_no()*restaurantInfo.getCg_discount()/10, 1).toString());
//                .setText(R.id.dis_viprice, turn(item.getDishes_vipprice() * item.getOrder_no(), 1).toString());
    }

    public BigDecimal turn(double val, int i) {
        BigDecimal bd = new BigDecimal(val);
        bd = bd.setScale(i, BigDecimal.ROUND_HALF_UP);//BigDecimal.ROUND_HALF_UP 是4舍5入
        return bd;
    }
}
